package cn.wit.test;

import java.util.Arrays;

/**
 * 编写一个方法，合并两个数组
 * 暴力搜索
 * 
 * @author 16604
 *
 */

public class DemoAddTwoArrays {
	public static void main(String[] args) {
		int[] a = { 1, 5, 16 };
		int[] b = { 3, 4, 6, 7 };
		System.out.println(Arrays.toString(merge(a, b)));

	}

	public static int[] merge(int[] a1, int[] a2) {

		int[] c = new int[a1.length + a2.length];
		int i;
		int jx = 0;
		
		// 先加入a1数组
		for (i = 0; i < a1.length; i++) {
			c[i] = a1[i];
		}
		jx=i;

		// 再加入a2数组
		for (int j = 0; j < a2.length; j++) {
			c[jx++] = a2[j];
		}
		Arrays.sort(c);

		return c;
	}

}
